<?php

namespace App\Http\Controllers\Api\getParams;

use Illuminate\Http\Request;
use App\Jobs\OrderSubmit;
use Monolog\Logger;
use Monolog\Formatter\LineFormatter;
use Monolog\Handler\RotatingFileHandler;
use Carbon\Carbon;
use App\Repository\UpThree\MainOrderRepostition;
use App\Http\Controllers\Api\BaseController;
use Illuminate\Support\Facades\DB;

class KwaiController extends BaseController
{
  private $log;
  public function __construct()
  {
    $this->log = new Logger('KwaiGetCode');
    $this->log->pushHandler(
      (new RotatingFileHandler(storage_path('/logs/KwaiGetCode.log'), 14, Logger::DEBUG, true, 0777))->setFormatter(new LineFormatter(null, null, true, true))
    );
  }
  // 获取拼多多的code 
  public function getCode(Request $request)
  {

    $code = $request->has('code') && $request->get('code') != '' ? $request->get('code') : '';
    if (empty($code)) {
      $getData = file_get_contents('php://input');
      $codess = json_decode($getData, true);
      $this->log->info('快手获取详细参数1' . json_encode($codess));
    }
    $time = time();
    $this->log->info('快手获取详细参数' . json_encode($request));
    if ($request->has('state') && $request->get('state') != '') {
      $state = $request->get('state');
    }
    if (empty($start)) {
      return $this->returnMsg(100, '请联系管理员');
    }
    $isTrue = DB::Table('kwai_conf')->where(['id' => $state])->first();
    if (!$isTrue) {
      return $this->returnMsg(101, '未查询到数据,请联系管理员');
    }
    if (!empty($isTrue->code)) {
      return $this->returnMsg(102, '您已配置');
    }

    if ($code != '') {
      $isEdit = DB::table('kwai_conf')->where(['id' => $state])->update(['code' => $code]);
      return $code; // 直接返回code
    };

    return '未查询到';
  }
}
